<?php
class Linkdir_Controller_Plugin_SiteTemplate extends Zend_Controller_Plugin_Abstract{
	
	public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request){
		$viewRenderer=Zend_Controller_Action_HelperBroker::getStaticHelper(
			'ViewRenderer'
		);
		if (is_null($viewRenderer->view)) {
			$viewRenderer->init();
		}		
		$viewRenderer->view->baseUrl=$request->getBaseUrl();
		$optionModel=new Model_OPtion();
		$title=$optionModel->fetchOption('title');
		$tagline=$optionModel->fetchOption('tagline');
		if($title){
			$viewRenderer->view->siteTitle=$title->value;
		}
		if($tagline){
			$viewRenderer->view->tagline=$tagline->value;
		}
		$widgetModel=new Model_Widget();
		$controller=$request->getControllerName();
		$action=$request->getActionName();
		$widgets[]=null;
		if($controller=='link' && $action=='list'){
			$widgets[]=$widgetModel->fetchLinkListWidgets();			
		}else{
			$widgets[]=$widgetModel->fetchHomePageWidgets();
		}
		//foreach($id_ary as $id){
		//	$widgets[]=$widgetModel->fetchWidget($id);
		//}
		$viewRenderer->view->widgets=$widgets;
	}
	public function preDispatch(Zend_Controller_Request_Abstract $request){
		$viewRenderer=Zend_Controller_Action_HelperBroker::getStaticHelper(
			'ViewRenderer'
		);
		$auth=Zend_Auth::getInstance();
		if($auth->hasIdentity()){
			$viewRenderer->view->identity=$auth->getIdentity();
		}	
	}
}
?>